package com.ruoyi.system.controller;

import com.ruoyi.common.core.plus.web.controller.BasePlusController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.system.domain.SysDictLanguage;
import com.ruoyi.system.service.ISysDictLanguageService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author qy
 * @date 2023/3/17 15:26
 */

@RestController
@RequestMapping("/system/dict/language")
public class SysDictLanguageController extends BasePlusController {

    @Autowired
    private ISysDictLanguageService sysDictLanguageService;

    @GetMapping(value = "/{id}")
    @ApiOperation(value = "详细")
    @PreAuthorize("@ss.hasPermi('system:dict:language:list')")
    public AjaxResult query(@PathVariable Long id) {
        List<SysDictLanguage> dictLanguage = sysDictLanguageService.getByDictCode(id);
        return AjaxResult.success(dictLanguage);
    }

    @PostMapping
    @ApiOperation(value = "新增")
    @PreAuthorize("@ss.hasPermi('system:dict:language:add')")
    public AjaxResult save(@RequestBody SysDictLanguage sysDictLanguage) {
        sysDictLanguageService.save(sysDictLanguage);
        return AjaxResult.success();
    }

    @PutMapping
    @ApiOperation(value = "更新")
    @PreAuthorize("@ss.hasPermi('system:dict:language:edit')")
    public AjaxResult update(@RequestBody SysDictLanguage sysDictLanguage){
        sysDictLanguageService.update(sysDictLanguage);
        return AjaxResult.success();
    }

    @DeleteMapping
    @ApiOperation(value = "删除")
    @PreAuthorize("@ss.hasPermi('system:dict:language:remove')")
    public AjaxResult delete(@RequestParam Long dictCode,@RequestParam String type){
        sysDictLanguageService.delete(dictCode,type);
        return AjaxResult.success();
    }

}
